package com.hos.utile;

import java.util.Random;

/**
 * Created by guom on 2018/11/11.
 */
public class StringUtile {
    public static boolean isEmpty(String value) {
        if (value == null || value.length() == 0) {
            return true;
        }
        return false;
    }

    public static String getString(String[] value) {
        if (value == null) {
            return null;
        }
        String vs = "";
        for (int i = 0; i < value.length; i++) {
            String v = value[i];
            if (isEmpty(vs)) {
                vs = v;
                continue;
            }
            vs += "," + v;
        }
        return vs;
    }

    public static boolean isPhone(String phone) {
        if (isEmpty(phone)) {
            return false;
        }
        // "[1]"代表第1位为数字1，"[3578]"代表第二位可以为3、5、7、8中的一个，"\\d{9}"代表后面是可以是0～9的数字，有9位。
        String telRegex = "[1][3456789]\\d{9}";
        return phone.matches(telRegex);
    }
    //获取随机码
    public static String getRandom() {
        Random random = new Random();
        String randoms = "";
        for (int i = 0; i < 4; i++) {
            int randomInt = random.nextInt(9);
            randoms += randomInt;
        }
        return randoms;
    }
}
